﻿

window.SearchKey = null;
$.MGJ.DealerLevel = [];
(function () {
    var _this = $.MGJ.DealerLevel;
    $.extend($.MGJ.DealerLevel, {
        ExportExecl: function (ele) {
            $("input.AllClickChild:checked").each(function () {
                info.push($(this).attr('ID'));

            });
            if (info.length == 0) {
                $.L.msgError("请选择要导出的数据信息！");
                return
            }
           
            if (!$(ele).find('.no-result').hasClass('no-result')) {
                window.open(ACTION_URL("ExportExecl", "Manager") + "?Key=" + info);
            }
            else {
                $.L.msgWarning('导出数据不能为空！')
            }
        }
    });
})(jQuery);

(function () {
    var _this = $.MGJ.DealerLevel;
    $.extend($.MGJ.DealerLevel, {
        Dialog_AEditLevelObj: null,
        Dialog_AEditLevel: function () {
            var i = 0;
            i++;
         
            //var i = 0;
            //function ch() {
            //    i++;
            //    alert(i);
            //}
            
            this.Dialog_AEditLevelObj = $.L.dialog({
                url: ACTION_URL("AEditLevel", "Manager"),
                title: "新增经销商等级管理",
                width: 700,
                height: 'auto',
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#form_Level").data('bootstrapValidator').validate();
                            if (bootstrapValidator.isValid()) {
                                $.MGJ.DealerLevel.Ajax_AddLevelName();
                                $(".btn-primary").attr("disabled", true);
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        },
        Dialog_EditLeveObj: null,
        Dialog_EditLeve: function (obj) {
            var id = $(obj).attr("DID");
            this.Dialog_EditBatchObj = $.L.dialog({
                url: ACTION_URL("Edit", "Manager") + "?id=" + id,
                title: "编辑",
                width: 800,
                height: "auto",
                buttons: {
                    "button_save": {
                        type: 'primary',
                        text: '保存',
                        click: function () {
                            var bootstrapValidator = $("#form_editLevel").data('bootstrapValidator').validate();
                            if (bootstrapValidator.isValid()) {
                                $.MGJ.DealerLevel.Ajax_EditLeve(id);
                                $(".btn-primary").attr("disabled", true);
                            }
                            else {
                                $.L.msgError("请检查数据格式！");
                            };
                        }
                    },
                    "button_cancel": {
                        type: 'default',
                        text: '取消',
                        click: 'MODALMISS'
                    }
                }
            });
        }

    });
})(jQuery);

(function () {
    var _index = 1;
    var _this = $.MGJ.DealerLevel;
    $.extend($.MGJ.DealerLevel, {
        Ajax_DealerLevelList: function (pageIndex) {
            _index = pageIndex;
            window.SearchKey = removeSpace($("#dsearch").val());
            $.L.ajaxHandle({
                url: ACTION_URL("DealerLevelList", "Manager"),
                data: {
                    dsearch: window.SearchKey,
                    pageIndex: pageIndex,
                    pageSize: 10
                },
                success: function (response) {
                    $("#DealerLevelTable").L_bindingDataList(response);
                }
            });
        },
        ////修改
        Ajax_EditLeve: function (id) {
            $.L.ajaxHandle({
                url: ACTION_URL("EditLeve", "Manager") + "?id=" + id,
                data: $("#form_editLevel").serialize(),
                success: function (response) {
                    if (response > 0) {
                        _this.Dialog_EditBatchObj.close();
                        $.L.msgSuccess("操作成功！");
                        _this.Ajax_DealerLevelList(1);
                    }

                }
            });
        },
        ////删除
        Ajax_DelLeve: function (obj) {
            $.L.msgConfirm("确认删除该记录?", function () {
                var id = $(obj).attr("DID");
                $.L.ajaxHandle({
                    url: ACTION_URL("DelLeve", "Manager") + "?id=" + id,
                    data: { id: id },
                    success: function (response) {
                        if (response == "0") {
                            $.L.msgSuccess("删除成功！");
                            _this.Ajax_DealerLevelList(_index);
                            
                        } else if (response == "4445") {
                            $.L.msgWarning("已被使用资源不可删除");
                        } else if (response == "4444") {
                            $.L.msgError("删除失败！");
                        }
                    }
                });
            })
        },
        //添加
        Ajax_AddLevelName: function (id) {
            $.L.ajaxHandle({
                url: ACTION_URL("AddLevelName", "Manager"),
                data: $("#form_Level").serialize(),
                success: function (response) {
                    if (response > 0) {
                        _this.Dialog_AEditLevelObj.close();
                        $.L.msgSuccess("操作成功！");
                        _this.Ajax_DealerLevelList(1);
                    }
                    else {
                        $.L.msgSuccess("操作失败！");
                    }
                }
            });
        }
    });
})(jQuery);

(function () {
    var _this = $.MGJ.DealerLevel;
    $.extend($.MGJ.DealerLevel, {


    });
})(jQuery);